package reflect;

/**
 * Created by steve
 * 2018/10/17 5:19 PM
 */
public class ClassDemo1 {

    public static void main(String[] args) {

        Foo foo1 = new Foo();

        // 如何表示类
        Class c1 = Foo.class;

        // two
        Class c2 = foo1.getClass();

        System.out.println(c1 == c2);

        // three
        Class c3 = null;

        try {
            c3 = Class.forName("reflect.Foo");
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }

        System.out.println(c2 == c3);


        try {
            Foo foo = (Foo)c1.newInstance();
            foo.say();
        } catch (InstantiationException e) {
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        }
    }

}

class Foo {

    void say() {
        System.out.println("hello reflect");
    }
}
